package com.ygq.controller;


import DTO.AddTest2DTO;
import DTO.AddTestDTO;
import VO.QuestionNumberVO;
import com.ygq.PublishTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.Result;


/**
 * 添加试卷页面
 */
@RestController
@RequestMapping("/teacher/publishtest")
public class PublishTestController {

    @Autowired
    private PublishTestService publishTestService;


    /**
     * 获取所有编号
     * @return
     */
    @GetMapping("/getQuestionNumber")
    public Result<QuestionNumberVO> getQuestionNumber(Integer startRange,Integer endRange){
        if (startRange>endRange){
            return Result.error("错误");
        }
        return Result.success(publishTestService.getQuestionNumber(startRange,endRange));
    }


    // 根据题目id 和题目类型返回该题目的信息
    @GetMapping("/getQuestion")
    public Result<Object> getQuestion(Integer id, Integer questionType){
        return Result.success(publishTestService.getQuestion(id,questionType));
    }


    // 添加试卷
    @PutMapping("/addTest")
    public Result<String> addTest(@RequestBody AddTestDTO addTestDTO){
        if (!addTestDTO.getStartTime().isBefore(addTestDTO.getEndTime())){
            return Result.error("时间格式不正确，",303);
        }
        if (addTestDTO.getWorkType()==1){
            // 第一给测试
            publishTestService.saveTest1(addTestDTO);
        }
        return Result.success("ok");
    }

    // 添加试卷2
    @PutMapping("/addTest2")
    public Result<String> addTest2(@RequestBody AddTest2DTO addTestDTO){
        if (!addTestDTO.getStartTime().isBefore(addTestDTO.getEndTime())){
            return Result.error("时间格式不正确，",303);
        }
        if (addTestDTO.getWorkType()==2){
            // 第二次测试
            publishTestService.saveTest2(addTestDTO);
            return Result.success(null);
        }
        return Result.error("数据错误");

    }
}
